#include <stdio.h>
#include <src/algo.h>
#include <src/iterator.h>
#include <src/List.h>

int main(int argc, char *argv[]) {
	List list;
	listConstruct(&list);

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "========");

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "Insert");
	for (int i = 0; i < 10; ++i) {
		listInsert(listBegin(&list), i);
	}
	for (int i = 10; i < 20; ++i) {
		listInsert(listBegin(&list), i);
	}
	listInsertN(advance(List, listBegin(&list), 10), 10, 100);
	forEach (List, iterator, list) {
		printf("[INF] (%s, %d) %d\n", __FILE__, __LINE__, *listIteratorIndirect(&iterator));
	}

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "Sort");
	listSort(listBegin(&list), listEnd(&list));
	forEach (List, iterator, list) {
		printf("[INF] (%s, %d) %d\n", __FILE__, __LINE__, *listIteratorIndirect(&iterator));
	}

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "LowerBound");
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopLowerBound(List, listBegin(&list), listEnd(&list), 0)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopLowerBound(List, listBegin(&list), listEnd(&list), 10)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopLowerBound(List, listBegin(&list), listEnd(&list), 100)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopLowerBound(List, listBegin(&list), listEnd(&list), 1000)));

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "UpperBound");
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopUpperBound(List, listBegin(&list), listEnd(&list), 0)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopUpperBound(List, listBegin(&list), listEnd(&list), 10)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopUpperBound(List, listBegin(&list), listEnd(&list), 100)));
	printf("[INF] (%s, %d) %lu\n", __FILE__, __LINE__, distance(List, listBegin(&list), loopUpperBound(List, listBegin(&list), listEnd(&list), 1000)));

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "Erase");
	listEraseN(listBegin(&list), 10);
	listEraseIn(advance(List, listBegin(&list), 10), advance(List, listBegin(&list), 20));
	forEach (List, iterator, list) {
		printf("[INF] (%s, %d) %d\n", __FILE__, __LINE__, *listIteratorIndirect(&iterator));
	}

	printf("[INF] (%s, %d) %s\n", __FILE__, __LINE__, "========");

	listDestruct(&list);
	return 0;
}
